﻿using System;
using UnityEngine;

// Token: 0x020005EA RID: 1514
public class SteamVR_GazeTracker : MonoBehaviour
{
	// Token: 0x14000004 RID: 4
	// (add) Token: 0x0600269B RID: 9883 RVA: 0x000E17E8 File Offset: 0x000DF9E8
	// (remove) Token: 0x0600269C RID: 9884 RVA: 0x000E1820 File Offset: 0x000DFA20
	public event GazeEventHandler GazeOn;

	// Token: 0x14000005 RID: 5
	// (add) Token: 0x0600269D RID: 9885 RVA: 0x000E1858 File Offset: 0x000DFA58
	// (remove) Token: 0x0600269E RID: 9886 RVA: 0x000E1890 File Offset: 0x000DFA90
	public event GazeEventHandler GazeOff;

	// Token: 0x0600269F RID: 9887 RVA: 0x000E18C8 File Offset: 0x000DFAC8
	private void Start()
	{
	}

	// Token: 0x060026A0 RID: 9888 RVA: 0x000E18CC File Offset: 0x000DFACC
	public virtual void OnGazeOn(GazeEventArgs e)
	{
		if (this.GazeOn != null)
		{
			this.GazeOn(this, e);
		}
	}

	// Token: 0x060026A1 RID: 9889 RVA: 0x000E18E8 File Offset: 0x000DFAE8
	public virtual void OnGazeOff(GazeEventArgs e)
	{
		if (this.GazeOff != null)
		{
			this.GazeOff(this, e);
		}
	}

	// Token: 0x060026A2 RID: 9890 RVA: 0x000E1904 File Offset: 0x000DFB04
	private void Update()
	{
		if (this.hmdTrackedObject == null)
		{
			SteamVR_TrackedObject[] array = UnityEngine.Object.FindObjectsOfType<SteamVR_TrackedObject>();
			foreach (SteamVR_TrackedObject steamVR_TrackedObject in array)
			{
				if (steamVR_TrackedObject.index == SteamVR_TrackedObject.EIndex.Hmd)
				{
					this.hmdTrackedObject = steamVR_TrackedObject.transform;
					break;
				}
			}
		}
		if (this.hmdTrackedObject)
		{
			Ray ray = new Ray(this.hmdTrackedObject.position, this.hmdTrackedObject.forward);
			Plane plane = new Plane(this.hmdTrackedObject.forward, base.transform.position);
			float d = 0f;
			if (plane.Raycast(ray, out d))
			{
				Vector3 a = this.hmdTrackedObject.position + this.hmdTrackedObject.forward * d;
				float num = Vector3.Distance(a, base.transform.position);
				if (num < this.gazeInCutoff && !this.isInGaze)
				{
					this.isInGaze = true;
					GazeEventArgs e;
					e.distance = num;
					this.OnGazeOn(e);
				}
				else if (num >= this.gazeOutCutoff && this.isInGaze)
				{
					this.isInGaze = false;
					GazeEventArgs e2;
					e2.distance = num;
					this.OnGazeOff(e2);
				}
			}
		}
	}

	// Token: 0x0400269C RID: 9884
	public bool isInGaze;

	// Token: 0x0400269F RID: 9887
	public float gazeInCutoff = 0.15f;

	// Token: 0x040026A0 RID: 9888
	public float gazeOutCutoff = 0.4f;

	// Token: 0x040026A1 RID: 9889
	private Transform hmdTrackedObject;
}
